/*
 * Copyright (C) 2012 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.util;

import rpg.RPG;
import rpg.gfx.Bitmap;

/**
 *
 * @author rothens
 */
public class HotSpot {

    Bitmap textOn;
    Bitmap textOff;
    boolean active;
    int X, Y, right, bottom;

    public HotSpot(byte textId, String text, Integer X, Integer Y, Bitmap on, Bitmap off, int textOnC, int textOffC) {
        active = false;
        textOn = new Bitmap(on.width, on.height);
        textOff = new Bitmap(off.width, off.height);
        Bitmap textOnT = RPG.fs.getText(text, textId, textOnC);
        Bitmap textOffT = RPG.fs.getText(text, textId, textOffC);
        textOn.draw(on, 0, 0)
                .draw(textOnT, textOn.width / 2 - textOnT.width / 2, textOn.height / 2 - textOnT.height / 2);

        textOff.draw(off, 0, 0)
                .draw(textOffT, textOff.width / 2 - textOffT.width / 2, textOff.height / 2 - textOffT.height / 2);
        this.Y = (Y == null) ? RPG.WINDOW_HEIGHT/2 - textOn.height / 2 : Y;

        this.X = (X == null) ? RPG.WINDOW_WIDTH / 2 - textOn.width / 2 : X;
        right = this.X + textOn.width;
        bottom = this.Y + textOn.height;
    }

    public boolean isMouseOver(int x, int y) {
        return x >= X && x < right && y >= Y && y < bottom;

    }

    public Bitmap getPic() {
        if (active) {
            return textOn;
        } else {
            return textOff;
        }
    }

    public void activate() {
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public int getX() {
        return X;
    }

    public void setX(Integer X) {
        this.X = (X == null) ? RPG.WINDOW_WIDTH / 2 - textOn.width / 2 : X;
        right = this.X + textOn.width;
    }

    public int getY() {
        return Y;
    }

    public void setY(Integer Y) {
        this.Y = (Y == null) ? RPG.WINDOW_HEIGHT / 2 - textOn.height / 2 : Y;
        bottom = this.Y + textOn.height;
    }
}
